package com.csc.config;

import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;


@Configuration
@ComponentScan(
        // 指定要扫描的包
        basePackages = "com.csc",
        // 扫描除了controller的类
        excludeFilters ={
                @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = Controller.class),
                @ComponentScan.Filter(type = FilterType.ANNOTATION,classes = RestController.class)
        }
)
@PropertySource("classpath:database.properties")
@Import({JdbcConfig.class, MybatisConfig.class})
@EnableAspectJAutoProxy //开启aop
@EnableTransactionManagement //开启事务
public class SpringConfig {
    @Bean
    public DataSourceTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}
